$(function() {
	
	loadbzt(); 
	
});
var dom = null;
var myChart = null;


var json = {
		name: [],
		value: []
	};


function loadbzt() {
	 var obj = {};
	     obj.dprtcode =  $("#dprtcode").val();
	     
    $.ajax({
        cache: true,
        type: "POST",
        url: ctx + "getChartData",
        async: false,
        data: obj,
        error: function (request) {
            $.modal.alertError("系统错误");
        },
        success: function (data) {
        	dom = document.getElementById("container");
        	myChart = echarts.init(dom);
            json = {
            		name: [],
            		value: []
            };
        
            if (data.length > 0) { 
            		var kfNums=0;
            		var testNums=0;
            		 $.each(data, function (index, row) {
            			 json.name.push(row.name);
            			 if(row.name=="试验"){
            				 
            				 testNums=testNums+row.value;
            			 }else{
            				 
            				 kfNums=kfNums+row.value;
            			 }
                     })
                     json.value=data;
            		 $("#kfNums").text(kfNums);//库存数量
            		 $("#testNums").text(testNums);//试验数量
            }
            
            initecharts();
        }
    });
}


function initecharts() {
	option = null;
	option = {
		    tooltip: {
		        trigger: 'item',
		        formatter: "{a} <br/>{b}: {c} ({d}%)"
		    },
		    legend: {
		        orient: 'horizontal',
		        x: 'left',
		        data:json.name,
		        itemWidth: 7,
		        itemHeight: 7,
		        textStyle:{//图例文字的样式
		            color:'#fff',
		            fontSize:11
		        }
		    },
		    color:['#19bd8a','#f2d129','#e25035','#46afdb'],
		    series: [
		        {
		            name:'',
		            type:'pie',
		            radius: ['50%', '70%'],
		            avoidLabelOverlap: false,
		            label: {
		                normal: {
		                    show: false,
		                    position: 'center'
		                },
		                emphasis: {
		                    show: true,
		                    textStyle: {
		                        fontSize: '24',
		                        color:'#00fcff',
		                        fontWeight: 'bold'
		                    }
		                }
		            },
		            labelLine: {
		                normal: {
		                    show: false,
		                }
		            },
		            data:json.value
		                  	
		        }
		    ]
		};
	
	if (option && typeof option === "object") {
	    myChart.setOption(option, true);
	}
}
